<?php if ($this->form == null): ?>
	<dd class="<?php echo $this->id; ?>">
		<input id="<?php echo $this->id; ?>" class="form-control" type="text">
		<input type="hidden" class="input_text">
	</dd>
<?php else: ?>
	<div class="form-group <?php echo $this->id; ?>">
		<?php echo $this->form->labelEx($this->model,$this->id); ?>
		<input id="<?php echo $this->id; ?>" class="form-control" type="text">
		<?php echo $this->form->hiddenField($this->model,$this->id,array('class'=>'form-control','size'=>60,'maxlength'=>150)); ?>
		<?php echo $this->form->error($this->model,$this->id); ?>
	</div>
<?php endif; ?>
<script type="text/javascript">
		$("#<?php echo $this->id; ?>").on('tokenfield:createtoken', function (e) {
			if ($(".<?php echo $this->id; ?> .token").length == 1) {
				alert('Bạn chỉ lựa chọn một!');
				$("#<?php echo $this->id; ?>-tokenfield").val('');
				return false;
			};
		  }).on('tokenfield:removetoken', function (e) {
			checkMany = 0;
		  }).tokenfield({
				autocomplete: {
			     source: function(request, response) {
			    	$.ajax({
			    		url: '<?php echo $this->action; ?>',
			    		type: 'POST',
			    		dataType: 'json',
			    		data: {p:$("#<?php echo $this->id; ?>-tokenfield").val()},
			    		success: function(data) {
			              	response($.map(data,function (items) {
			              		return{
			              			value: items.name,
			              			id :items.id,
			              		}
			              	}));
			    		}
			    	});
			    },
			    select: function( event, ui ) {
					console.log(ui.item);
					$(".<?php echo $this->id; ?> input[type=hidden]").val(ui.item.id);
					if ("<?php echo $this->id; ?>" == "doitac_input") {
						$.fn.yiiGridView.update('doitac-grid1',{data: {id:ui.item.id}});
					};
					return false;
				},
			    delay: 100
			  },
			  allowEnter: false,
			  showAutocompleteOnFocus: true
		});
		  $('#<?php echo $this->id; ?>').tokenfield('createToken', <?php echo $value; ?>);
		</script>